{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Despacito \n",
      " Quiero respirar tu cuello despacito \n",
      " Deja que te diga cosas al oído \n",
      " Para que te acuerdes si no estás conmigo \n",
      " Despacito \n",
      " Quiero desnudarte a besos despacito\n",
      " Firmo en las paredes de tu laberinto\n",
      "  Y hacer de tu cuerpo todo un manuscrito sube sube sube\n",
      " Sube sube\n",
      " Quiero ver bailar tu pelo\n",
      " Quiero ser tu ritmo\n",
      " Que le ense es a mi boca\n",
      "Despacito \n",
      " Quiero respirar tu cuello despacito \n",
      " Deja que te diga cosas al oído \n",
      " Para que te acuerdes si no estás conmigo \n",
      " Despacito \n",
      " Quiero desnudarte a besos despacito\n",
      " Firmo en las paredes de tu laberinto\n",
      "  Y hacer de tu cuerpo todo un manuscrito sube sube sube\n",
      " Sube sube\n",
      " Quiero ver bailar tu pelo\n",
      " Quiero ser tu ritmo\n",
      " Que le ense es a mi boca\n"
     ]
    }
   ],
   "source": [
    "def print_refrain():\n",
    "    print(\"Despacito \\n Quiero respirar tu cuello despacito \\n Deja que te diga cosas al oído \\n Para que te acuerdes si no estás conmigo \\n Despacito \\n Quiero desnudarte a besos despacito\\n Firmo en las paredes de tu laberinto\\n  Y hacer de tu cuerpo todo un manuscrito sube sube sube\\n Sube sube\\n Quiero ver bailar tu pelo\\n Quiero ser tu ritmo\\n Que le ense es a mi boca\")\n",
    "\n",
    "print_refrain()\n",
    "print_refrain()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[6.0, 11, 11.0]\n",
      "[40.27272727272727, 11, 604.0181818181817]\n",
      "<class 'list'>\n"
     ]
    }
   ],
   "source": [
    "#data_input = input(\"请输入数值，用空格隔开:\")\n",
    "#sample = data_input.split(\" \")#lst1用来存储输入的字符串，用空格分割\n",
    "\n",
    "def compute_statistics(sample):\n",
    "    \n",
    "    n=len(sample)\n",
    "    sum=0\n",
    "    for element in sample:\n",
    "        sum+=float(element)\n",
    "    mean=sum/n\n",
    "   \n",
    "    sum=0\n",
    "    for element in sample:\n",
    "        sum+=(float(element)-mean)*(float(element)-mean)\n",
    "    variance=sum/(n-1)\n",
    "    return [mean, n,variance]\n",
    "print(compute_statistics([1,2,3,4,5,6,7,8,9,10,11]))\n",
    "print(compute_statistics([11,12,12,13,45,64,44,44,55,66,77]))\n",
    "#print(type(compute_statistics([11,12,12,13,45,64,44,44,55,66,77])))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[6.0, 11, 3.3166247903554]\n",
      "[40.27272727272727, 11, 604.0181818181817]\n"
     ]
    }
   ],
   "source": [
    "\n",
    "def compute_statistics(sample,std):\n",
    "    n=len(sample)\n",
    "    sum=0\n",
    "    for element in sample:\n",
    "        sum+=float(element)\n",
    "    mean=sum/n\n",
    "   \n",
    "    sum=0\n",
    "    for element in sample:\n",
    "        sum+=(float(element)-mean)*(float(element)-mean)\n",
    "    variance=sum/(n-1)\n",
    "    if not std:\n",
    "        return [mean, n,variance]\n",
    "    else:\n",
    "        return [mean,n,variance**0.5]\n",
    "print(compute_statistics([1,2,3,4,5,6,7,8,9,10,11],1))#输出标准差\n",
    "print(compute_statistics([11,12,12,13,45,64,44,44,55,66,77],0))#输出方差"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[6.0, 11, 3.3166247903554, 1.0, 11, 1]\n",
      "[40.27272727272727, 11, 604.0181818181817, 7.41017839202626, 77]\n"
     ]
    }
   ],
   "source": [
    "def compute_statistics(sample,std,SE,max_elem,min_ele):\n",
    "    lst=[]\n",
    "    n=len(sample)\n",
    "    sum=0\n",
    "    for element in sample:\n",
    "        sum+=float(element)\n",
    "    mean=sum/n\n",
    "    lst.append(mean)\n",
    "    lst.append(n)\n",
    "    sum=0\n",
    "    for element in sample:\n",
    "        sum+=(float(element)-mean)*(float(element)-mean)\n",
    "    variance=sum/(n-1)\n",
    "    if not std:\n",
    "        lst.append(variance)\n",
    "    else:\n",
    "        lst.append(variance**0.5)\n",
    "    if SE:\n",
    "        lst.append((variance/n)**0.5)\n",
    "    if max_elem:\n",
    "        lst.append(max(sample))\n",
    "    if min_ele:\n",
    "        lst.append(min(sample))\n",
    "    return lst\n",
    "print(compute_statistics([1,2,3,4,5,6,7,8,9,10,11],1,1,1,1))#全部输出\n",
    "print(compute_statistics([11,12,12,13,45,64,44,44,55,66,77],0,1,1,0))#输出部分"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
